from django.db import models
from django.contrib.auth.models import User

from mdeditor.fields import MDTextField

class Topic(models.Model):
    """主题"""
    text = models.CharField(max_length=20)
    date_added = models.DateTimeField(auto_now_add=True)
    Owner = models.ForeignKey(User,on_delete=models.CASCADE)
    
    def __str__(self):
        return self.text

class Blog(models.Model):
	"""Blog"""
	topic = models.ForeignKey(Topic,on_delete=models.CASCADE)
	text = MDTextField()
	title = models.CharField(max_length=20)
	date_added = models.DateTimeField(auto_now_add=True)
	Owner = models.ForeignKey(User,on_delete=models.CASCADE)
	
	class Meta:
		verbose_name_plural = 'blogs'
		
	def __str__(self):
		return self.title
			
class Comment(models.Model):
	blog = models.ForeignKey(Blog,on_delete=models.CASCADE)
	text = models.TextField(max_length=512)
	date_added = models.DateTimeField(auto_now_add=True)
	Owner = models.ForeignKey(User,on_delete=models.CASCADE)
	class Meta:
		verbose_name_plural = 'comments'
	def __str__(self):
		return str(self.text)
